Results 1 to 11 of 11

Thread: “Request for member”A” in “B” is of non-class type ”C”

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: “Request for member”A” in “B” is of non-class type ”C”

    That error is because t1 declared: Test t1(); is not an Test instance.
    If you use Test t1; //without () it would work.

    LE: stampede was faster
    The empty parentheses for default constructor can be used when you create objects on the heap, so:
    Qt Code:
    1. Test *ptr = new Test(); //is ok
    2. //so is this
    3. Test *ptr = new Test; //ok too
    To copy to clipboard, switch view to plain text mode 
    Isn't C++ a beautiful language?

  2. #2
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: “Request for member”A” in “B” is of non-class type ”C”

    Yeah, it's a quirk of the language. Because of the (weird) order that C/C++ evaluates and assigns type values, the "Test t1();" statement is interpreted as a call, not a declaration.

    It's just one of those "gotchas" that one learns of (sometimes several times) over the years.

  3. #3
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: “Request for member”A” in “B” is of non-class type ”C”

    @DanH: trying to call a function without definition will trigger a linker error about some unresolved external, so the is interpreted by the compiler as a function declaration, not as a function call.

  4. #4
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: “Request for member”A” in “B” is of non-class type ”C”

    Whatever -- you don't get what you want, and usually get a compile error.

  5. #5
    Join Date
    Mar 2011
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: “Request for member”A” in “B” is of non-class type ”C”

    Thanks for the hint without the braces after the call.

Similar Threads

  1. Replies: 7
    Last Post: 19th April 2011, 12:20
  2. 'Class' does not name a type error
    By naturalpsychic in forum Qt Programming
    Replies: 9
    Last Post: 1st February 2011, 15:43
  3. Replies: 12
    Last Post: 28th May 2010, 00:07
  4. Determine Class Type of QObject Parent
    By photo_tom in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2010, 17:42
  5. Replies: 2
    Last Post: 22nd December 2009, 20:52

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.